package com.dingding.order.core.pay.dao.impl;

import java.util.Date;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.base.dao.impl.BaseDaoImpl;
import com.dingding.common.core.beans.UserTaxiOrdert;
import com.dingding.common.core.beans.Userorder;
import com.dingding.order.code.order.OrderStatus;
import com.dingding.order.core.pay.dao.IPayUserOrderDao;

/**
 * 
 * @ClassName: IUserOrderDao 
 * @Description: 订单表支付操作DAO
 * @author CHEHAUNBO 
 * @date 2016年7月6日 下午4:57:25
 * @since V2.3.0
 * 
 */
@Component("payUserOrderDao")
public class PayUserOrderDaoImpl extends BaseDaoImpl<Userorder> implements IPayUserOrderDao {

	private Logger log = Logger.getLogger(PayUserOrderDaoImpl.class);

	/**
	 * 
	 * 订单支付成功后，将出租车订单添加到正式订单表中
	 * 
	 * @Title: orderPayUpdateOrderStatus 
	 * @param taxiOrderId 订单ID
	 * @author CHEHAUNBO
	 * 
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public void orderPayUpdateOrderStatus(UserTaxiOrdert taxiOrdert) {
		try {
			super.save(createUserorder(taxiOrdert));
		} catch (Exception e) {
			log.error("订单支付成功后，将出租车订单添加到正式订单表中出现异常！", e);
		}
	}

	/**
	 * 
	 * @Title: getUserorder
	 * @Description: 将taxiOrdert中的数据赋值给UserOrder
	 * @param taxiOrdert 订单临时表对象中的数据
	 * @author CHEHUANBO
	 * @return UserOrder 订单正式表对象
	 * @since V2.3.0
	 * 
	 */
	private Userorder createUserorder(UserTaxiOrdert taxiOrdert) {

		// 创建userOrder对象
		Userorder userOrder = new Userorder();
		// 主键Id
		userOrder.setOid(taxiOrdert.getTaxiOrdertId());
		// 下单用户Id
		userOrder.setPlaceOrderUserId(taxiOrdert.getPlaceOrderUserId());
		// 下单城市
		userOrder.setPayCity(taxiOrdert.getPlaceOrderCity());
		// 出发时间
		userOrder.setSetOutTime(taxiOrdert.getSetOutTime());
		// 出发地址
		userOrder.setStartAddress(taxiOrdert.getStartAddress());
		// 起点经度
		userOrder.setStartLongitude(taxiOrdert.getStartLongitude());
		// 起点纬度
		userOrder.setStartLatitude(taxiOrdert.getStartLatitude());
		// 目的地
		userOrder.setEndAddress(taxiOrdert.getEndAddress());
		// 目的地经度
		userOrder.setEndLongitude(taxiOrdert.getEndLongitude());
		// 目的地纬度
		userOrder.setEndLatitude(taxiOrdert.getEndLatitude());
		// 距离
		userOrder.setDistance(taxiOrdert.getDistance());
		// 叮币支付金额
		userOrder.setPayMoney(taxiOrdert.getPayMoney());
		// 支付宝支付金额
		userOrder.setAlipayMoney(taxiOrdert.getAlipayMoney());
		// 总金额
		userOrder.setTotalMoney(taxiOrdert.getTotalMoney());
		// 人数
		userOrder.setNumber(taxiOrdert.getNumber());
		// 留言
		userOrder.setMessage(taxiOrdert.getMessage());
		// 距对方距离
		userOrder.setPayDistance(taxiOrdert.getPayDistance());
		// 抢单用户Id
		userOrder.setGrabOrderUserId(taxiOrdert.getGrabOrderUserId());
		// 抢单时间
		userOrder.setGrabOrderTime(taxiOrdert.getGrabOrderTime());
		// 订单状态
		userOrder.setOrderStatus(OrderStatus.ORDER_STATUS_COMPLETE);
		// 下单时间
		userOrder.setCreateTime(taxiOrdert.getCreateTime());
		// 订单支付时间
		userOrder.setPayTime(taxiOrdert.getPayTime());
		// 乘客确认到达时间
		userOrder.setEndTime(new Date());
		// 下单用户类型
		userOrder.setOrderType(taxiOrdert.getOrderType());
		// 支付类型
		userOrder.setPayType(taxiOrdert.getPayType());
		//1：线上支付  2：线下支付
		userOrder.setTransactionType(taxiOrdert.getTransactionType());
		// 下单类型 2:出租车
		userOrder.setPublishType(2);

		return userOrder;

	}

}
